package com.ww.mock;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;

import com.alibaba.fastjson.JSONObject;
import com.ww.utils.HttpPrintUtils;

/**
 * 示例Handler
 * @author wangwei
 *
 */
public class DemoHandler extends AbstractHandler {

	@Override
	public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		// 获取传入参数 ?query=hello
		String query = request.getParameter("query");
		
		String result = "welcome to my server!";
		if(null != query && query.equals("hello")){
			result = query + "," + result;
		}
//		HttpPrintUtils.print(baseRequest, response, result);
		
		JSONObject json = new JSONObject();
		json.put("test", "test");
		HttpPrintUtils.printToJson(json.toJSONString(), response);
		
	}
	
	
}
